package it.eng.area118.mdocommon.ebus.stomp;

public class StompExample {

	// Create a connection
	public void createConnection() throws StompJException {
		Connection con = new Connection("127.0.0.1", 61666);

		con.connect();
	}

	// Example of method to send a message:

	public void sendmess() throws StompJException {
		Connection con = new Connection("127.0.0.1", 61666);

		con.connect();

		String freedomEventInXML = "<it.freedom.api.events.ObjectReceiveClick>"
				+ "<sender>AndroidTest</sender>" + "  <payload>"
				+ "    <payload>" + "     <it.freedom.reactions.Statement>"
				+ "      <logical>AND</logical>"
				+ "      <attribute>Object</attribute>"
				+ "      <operand>EQUAL</operand>"
				+ "      <value>Light 2</value>"
				+ "     </it.freedom.reactions.Statement>"
				+ "     <it.freedom.reactions.Statement>"
				+ "      <logical>AND</logical>"
				+ "      <attribute>click</attribute>"
				+ "      <operand>EQUAL</operand>"
				+ "      <value>SINGLE_CLICK</value>"
				+ "     </it.freedom.reactions.Statement>" + "    </payload>"
				+ " </payload>" + "</it.freedom.api.events.ObjectReceiveClick>";
		con.send(freedomEventInXML,
				"/topic/VirtualTopic.app.event.sensor.object.behavior.clicked");

	}

	// An example of subscription asyncronous to the queue:
	public void subscribe() throws StompJException {
		Connection con = new Connection("127.0.0.1", 61666);

		con.connect();

		con.subscribe("/queue/app.actuators.X10.X10Actuator.in", true);
		con.addMessageHandler("/queue/app.actuators.X10.X10Actuator.in",
				new MessageHandler() {
					public void onMessage(Message msg) {
						System.out.println(msg.getContentAsString());
					}
				});

	}
}
